<template>
  <div>
    <a-divider orientation="left" style="margin: 10px; color:#1677FF; font-size: 20px">热门-学历-类型-专业</a-divider>
    <div style="width: 80%; padding-left: 10px; margin-bottom: 8px">
      城市:&nbsp;&nbsp;&nbsp;
      <a-radio-group v-model:value="data.intentionLocation" buttonStyle="solid" @change="check(data)">
        <a-radio-button value="">不限</a-radio-button>
        <a-radio-button value="北京">北京</a-radio-button>
        <a-radio-button value="上海">上海</a-radio-button>
        <a-radio-button value="广州">广州</a-radio-button>
        <a-radio-button value="深圳">深圳</a-radio-button>
        <a-radio-button value="南京">南京</a-radio-button>
        <a-radio-button value="武汉">武汉</a-radio-button>
        <a-radio-button value="苏州">苏州</a-radio-button>
        <a-radio-button value="成都">成都</a-radio-button>
        <a-radio-button value="杭州">杭州</a-radio-button>
        <a-radio-button value="重庆">重庆</a-radio-button>
        <a-radio-button value="天津">天津</a-radio-button>
      </a-radio-group>
    </div>
    <div style="width: 80%; padding-left: 10px; margin-bottom: 8px">
      学历:&nbsp;&nbsp;&nbsp;
      <a-radio-group v-model:value="data.intentionHighestEducation" buttonStyle="solid" @change="check(data)">
        <a-radio-button value="">不限</a-radio-button>
        <a-radio-button value="专科">专科</a-radio-button>
        <a-radio-button value="本科">本科</a-radio-button>
        <a-radio-button value="硕士">硕士</a-radio-button>
        <a-radio-button value="博士">博士</a-radio-button>
      </a-radio-group>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      类型:&nbsp;&nbsp;&nbsp;
      <a-radio-group v-model:value="data.intentionJobType" buttonStyle="solid" @change="check(data)">
        <a-radio-button value="">不限</a-radio-button>
        <a-radio-button value="全职">全职</a-radio-button>
        <a-radio-button value="兼职">兼职</a-radio-button>
        <a-radio-button value="实习">实习</a-radio-button>
      </a-radio-group>
    </div>
  </div>

  <a-list :data-source="listData" :pagination="pagination" item-layout="vertical" size="small">
    <template #footer>
      <div style="width: 80%; padding-left: 10px;">
        <b>希望您在职场中找到属于自己的位置，实现人生价值！</b>
        祝您工作顺利，生活美满，前程似锦！
      </div>
    </template>
    <template #renderItem="{ item }">

      <a-list-item key="item.title" class="list-item">
        <template #extra>
          <div style=" display: flex;margin-right: 50px">
          </div>

        </template>
        <a-list-item-meta>
          <template #description>
            {{ item.intentionMajor }} &nbsp;&nbsp;
            {{ item.intentionHighestEducation }} &nbsp;&nbsp;
            {{ item.intentionJobType }}
          </template>
          <template #title>
            <router-link :to="{path:'/enterprise/queryIntention/detail/'+item.intentionStudentId}" style="color: #1677FF;font-size: 25px">{{ item.intentionName}}---查看简历</router-link>
            <span style="color: red; float: right">期望-岗位：{{ item.intentionJobTitle }}</span>
            <span style="float: right; margin-right: 30px;">期望-地点：{{ item.intentionLocation }}</span>
            <span style="float: right; margin-right: 30px;">期望-薪资：{{ item.intentionExpectedSalary }}</span>
          </template>
        </a-list-item-meta>
        <div style="width: 80%;">
        联系电话：{{ item.intentionContactInfo }} &nbsp;&nbsp;&nbsp;&nbsp;
        可开始工作时间 : &nbsp {{ formatInterviewDate(item.intentionAvailableStartDate) }}
        </div>
      </a-list-item>
    </template>
  </a-list>
</template>
<script setup>
import {onMounted, ref} from "vue";
import {pageJobAPI, queryJobIndustryByEnterpriseIdAPI, queryJobTitleByEnterpriseIdAPI} from "@/apis/job.js";
import http from "@/utils/http.js";
import {pageCollectAPI} from "@/apis/collect.js";
import {useUserStore} from "@/stores/user.js";
import {queryResumeByStudentUserIdAPI} from "@/apis/student.js";
import {pageIntentionAPI, queryIntentionByJobIndustryAPI, queryIntentionByJobTitleAPI} from "@/apis/intention.js";
import {queryInformationByUserIdAPI} from "@/apis/enterprise.js";


//获取数据
//获取数据
const useStore = useUserStore();
const enterpriseUserId = ref(useStore.userInfo.userId);
const enterpriseId = ref('');
const listData = ref([]);
const jobTitle=ref([]);
const industry=ref([]);
const data = ref({pageCurrent: 1, pageSize: 5, intentionHighestEducation: '', intentionLocation: '',intentionJobType:'',intentionStatus:'公开'});
const getData = async (data) => {
  //查询出企业ID
  const res = await queryInformationByUserIdAPI(enterpriseUserId.value)
  enterpriseId.value=res.data.data.enterpriseId
  //1.获取该企业的岗位标题
  const res1=await queryJobTitleByEnterpriseIdAPI(enterpriseId.value)
  jobTitle.value=res1.data.data
  // 使用 Set 进行去重
  jobTitle.value = [...new Set(jobTitle.value)];
  //2.获取该企业的岗位所属行业
  const res2=await queryJobIndustryByEnterpriseIdAPI(enterpriseId.value)
  industry.value=res2.data.data
  // 使用 Set 进行去重
  industry.value = [...new Set(industry.value)];
  const res3=await queryIntentionByJobTitleAPI(jobTitle.value)
  // 正确初始化 listData.value 为数组
  listData.value = [];
  if (Array.isArray(res3.data.data)) {
    listData.value.push(...res3.data.data);
  } else {
    // 若不是数组，直接添加
    listData.value.push(res3.data.data);
  }
  const res4=await queryIntentionByJobIndustryAPI(industry.value)
  if (Array.isArray(res4.data.data)) {
    listData.value.push(...res4.data.data);
  } else {
    // 若不是数组，直接添加
    listData.value.push(res4.data.data);
  }
  const res5 = await pageIntentionAPI(data)
  pagination.total = res5.data.data.total
  if (Array.isArray(res5.data.data.data)) {

    listData.value.push(...res5.data.data.data);
  } else {
    // 若不是数组，直接添加
    listData.value.push(res5.data.data.data);
  }
  // 根据对象的 id 属性进行去重
  const uniqueIds = [];
  listData.value = listData.value.filter(item => {
    if (!uniqueIds.includes(item.id)) {
      uniqueIds.push(item.id);
      return true;
    }
    return false;
  });
}

// 新增方法用于截断文本并添加省略号
const truncateText = (text) => {
  return text.slice(0, 20) + '. . . . .';
};
const pagination = {
  onChange: page => {
    console.log(page);
    data.value.pageCurrent = page
    getData(data.value)
  },
  pageSize: 5,
  total: 0,
};
// 生命周期
onMounted(() => {
  getData(data.value);
});


//筛选
const check = data => {
  console.log(data.job_address)
  console.log(data.job_industry)
  getData(data);
}
//时间格式
const formatInterviewDate = (dateString) => {
  const date = new Date(dateString);

  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');
  const minutes = String(date.getMinutes()).padStart(2, '0');

  return `${year}-${month}-${day} ${hours}:${minutes}`;
};
</script>
<style scoped>
.list-item {
  margin: 10px 10px 0;
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.1);
  border-radius: 10px; /* 你可以调整这个值来改变圆角的大小 */

  h4 {
    background-color: #F5F5F5;
    padding: 9px;
    border-radius: 5px;
  }
}
</style>
